package com.bj58.mis.bigdata.mdp.sys.controller;


import com.bj58.mis.bigdata.mdp.sys.common.consts.ResultCodeConsts;
import com.bj58.mis.bigdata.mdp.sys.common.result.ResultBean;
import com.bj58.mis.bigdata.mdp.sys.util.JsonUtil;
import com.bj58.mis.bigdata.mdp.sys.vo.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.client.RestTemplate;

import java.util.UUID;

public abstract class SSOController {
    /**
     * reids tokens key
     */
    public static final String REDIS_TOKEN_KEY = "SSO:TOKEN:";

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    protected StringRedisTemplate redisTemaplte;

    @Autowired
    protected RestTemplate restTemplate;



    protected String saveLoginUserToRedis(LoginUser loginUser) {
        String jsonLoginUser = JsonUtil.toJson(loginUser);
        String token = UUID.randomUUID().toString().replace("-", "");
        String key = REDIS_TOKEN_KEY+token;
        redisTemaplte.opsForValue().set(key, jsonLoginUser);
        logger.info("保存登录用户信息到redis： key={}, value={}", key, jsonLoginUser);
        return token;
    }




}
